<template>
    <div class="shopCar">
        <div class="top" style="over-flow:hidden;">
            <img :src="require('@/assets/shop/back.png')" alt="" class="back" @click="$router.go(-1)" />
            <div class="p" style="text-align:center;width:100%;margin-left:-10%;line-height:20px;">用户信息</div>
        </div>
        <div class="bar">
            <div class="right" style=" border-top: 7px solid #f5f5f5;">
                <input type="file" accept="image/*" @change="onUploadImg" class="hiddenInput" />
                <div class="total" @click.stop="uploadHeadImg">
                    <span class="title"> 头&nbsp;&nbsp;&nbsp;&nbsp;像: </span>

                    <van-uploader v-model="fileList" :max-count="1" :after-read="onUploadImg" @delete="onPhotoDelete">

                        <div class="upload_once">
                            
                            <img :src="user_face(user_pic)" style="  height:42px; width:42px; " alt="" />
                        </div>
                    </van-uploader>

                </div>
                <div class="total">
                    <span class="title"> 用户名: </span>
                    <input class="inp" type="text" placeholder="请填写用户名" v-model="username" />
                </div>
                <div class="total" v-if="this.$store.state.detail.user.login_type !=80">
                    <span class="title"> 密&nbsp;&nbsp;&nbsp;&nbsp;码:</span>

                    <input class="inp" type="text" placeholder="默认密码不修改" v-model="LOGIN_PASS" />
                </div>

                <div class="total">
                    <span class="title"> 手机号: </span>
                    <input class="inp" type="text" placeholder="请填写手机号" v-model="MOBILE_NUM" />
                </div>
                <div class="total">
                    <span class="title"> 生&nbsp;&nbsp;&nbsp;&nbsp;日: </span>
                    <input class="inp time" type="date" style="" placeholder="请填写生日" v-model="BIRTHDAY" />
                </div>
                <!-- <div class="total">
                    <span class="title">姓&nbsp;&nbsp;&nbsp;&nbsp;名:</span>
                    
                    <input class="inp" type="text" placeholder="请填写开户人真实姓名" v-model="BANK_NAME" />
                </div>    
                <div class="total">
                    <span class="title">开户行:</span>
                    
                    <input class="inp" type="text" placeholder="请填写开户行" v-model="BANK_USER_NAME" />
                </div>
                <div class="total">
                    <span class="title">银行卡:</span>
                    
                    <input class="inp" type="text" placeholder="请填写银行卡号" v-model="BANK_NUM" />
                </div> -->
                <div class="btn" @click="saveinfo"> 保存</div>

            </div>
        </div>
        <!-- 底部栏 -->
        <v-footer2 background="#f2f2f2"></v-footer2>
    </div>
</template>
<script>
import "@/css/shop/main.scss";
import "@/css/shop/info.scss";
import Footer2 from "@/common/travel/_footer2.vue";

import { Toast } from 'vant'
export default {
    components: {
        "v-footer2": Footer2,
    },
    data() {
        return {
            domainUrl: this.$conf.domain,
            username: "",
            BANK_NAME: "",
            BANK_NUM: "",
            BANK_USER_NAME: "",
            LOGIN_PASS: "",
            BIRTHDAY: "",
            MOBILE_NUM: "",
            user_pic: "",
            fileList: [],
 

        };
    },
    created() {
        this.onLoad();
    },
    methods: {
        onSubmit() { },
        //点击选项
        checkPic: function (picurl) {
            return this.$conf.domain + "/" + picurl;
        },
        onLoad() {
            let obj = { 'api_user': this.$store.state.login.username };
            this.$dopost('/sysapi/user/userinfo/', obj,
                function (response) {
                    if (response.data && typeof (response.data.error) != "undefined" && response.data.error === 0) {
                        this.$store.state.detail.user = response.data.data;
                        this.role_id = response.data.data.role_id;
                        this.username = response.data.data.name;
                        // this.LOGIN_PASS = response.data.data.LOGIN_PASS;
                        this.BANK_NAME = response.data.data.BANK_NAME;
                        this.BANK_USER_NAME = response.data.data.BANK_USER_NAME;
                        this.BANK_NUM = response.data.data.BANK_NUM;
                        this.BIRTHDAY = response.data.data.BIRTHDAY;
                        this.MOBILE_NUM = response.data.data.mobile;
                        this.user_pic = response.data.data.pic;


                    }
                    else { Toast((response.data && response.data.mess) ? response.data.mess : '出错了！'); }
                }.bind(this), true);
        },
        saveinfo() {
            let obj = {
                api_user: this.$store.state.login.username,
                username: this.username,
                LOGIN_PASS: this.LOGIN_PASS,
                BANK_NAME: this.BANK_NAME,
                BANK_USER_NAME: this.BANK_USER_NAME,
                BANK_NUM: this.BANK_NUM,
                MOBILE_NUM: this.MOBILE_NUM,
                BIRTHDAY: this.BIRTHDAY,
                user_pic: this.user_pic,
            };
            this.$dopost('/sysapi/user/newedit/', obj,
                function (response) {
                    if (response.data && typeof (response.data.error) != "undefined" && response.data.error === 0) {
                        Toast('修改成功');
                        if (this.LOGIN_PASS != '') {
                            this.$store.commit('CHANGE_USER', 0, '', '');
                            this.$router.replace({ path: '/login' });

                        }

                    }
                    else { Toast((response.data && response.data.mess) ? response.data.mess : '出错了！'); }
                }.bind(this), true);

        },
        onUploadImg(e) {
            console.log(e)
            var that = this;
            var road_data = that.$store.state.index.road_data
            var formData = new FormData();
            formData.append('Filedata', e.file);
            that.$fly.post(`${that.domainUrl}/system/upload/file?pic_type=999999999`, formData).then(res => {
                console.log('上传', res)
                var srcType = res.data.substring(0, 7)
                if (srcType == 'upload/') {
                    road_data.picImg = res.data
                    road_data.file = that.fileList
                    this.user_pic = res.data
                } else {
                    that.$toast('上传0失败:' + res.data)
                    that.fileList.pop()
                }
            }).catch(err => {
                that.$toast('上传1失败！')
                that.fileList.pop()
            })
        },
        //删除图片
        onPhotoDelete(e, item) {
            var road_data = that.$store.state.index.road_data
            road_data.picImg.splice(item.index, 1)
        },
        //删除图片
        onPhotoDelete(e, item) {
            var that = this;
            that.imgList.splice(item.index, 1)
            that.store.imgList.splice(item.index, 1)
        },
            user_face(url) {
            var index = url.indexOf("://")
            if (index == -1) {
                return this.domainUrl + '/' + url
            } else {
                return url
            }

        },
 


    },
};
</script>
<style lang="less" scoped>
.hiddenInput {
    position: absolute;
    left: 0rem;
    top: 0.1rem;
    width: 100%;
    height: 0.6rem;
    opacity: 0;
}
</style>
 